package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.plm.entity.ProjectInfo;
import com.mxpio.erp.common.plm.entity.ProjectInfoCompleteDeliverableDraft;
import com.mxpio.erp.common.plm.entity.ProjectInfoEnd;
import com.mxpio.erp.common.plm.service.ProjectInfoCompleteDeliverableDraftService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "ProjectInfoCompleteDeliverableDraftController", description = "项目-结项-交付物草稿表")
@RestController
@RequestMapping("/erp/plm/pro/info/complete/deliverable/draft")
public class ProjectInfoCompleteDeliverableDraftController {
    @Autowired
    private ProjectInfoCompleteDeliverableDraftService draftService;

    @PutMapping("edit")
    @Operation(summary = "编辑信息", description = "编辑信息", method = "PUT")
    public Result<ProjectInfoCompleteDeliverableDraft> edit(@RequestBody ProjectInfoCompleteDeliverableDraft draft) {
        draftService.update(draft);
        return Result.OK(draft);
    }

    @GetMapping("list/all/{proCode}")
    @Operation(summary = "根据项目编码-获取交付物信息", description = "根据项目编码-获取交付物信息", method = "GET")
    public Result<List<ProjectInfoCompleteDeliverableDraft>> getList(@PathVariable(name = "proCode", required = true) String proCode) {
        List<ProjectInfoCompleteDeliverableDraft> list = draftService.list(ProjectInfoCompleteDeliverableDraft.class, Criteria.create().addCriterion("proCode", Operator.EQ, proCode));
        return Result.OK(list);
    }

    @GetMapping("one/{bizNo}")
    @Operation(summary = "根据项目编码-获取正在审批的交付物信息", description = "根据项目编码-获取正在审批的交付物信息", method = "GET")
    public Result<List<ProjectInfoCompleteDeliverableDraft>> getOne(@PathVariable(name = "bizNo", required = true) String bizNo) {
        List<ProjectInfoCompleteDeliverableDraft> draft = draftService.getOne(bizNo);
        return Result.OK(draft);
    }
}
